package com.dalongxin.work.page.adapter.selection;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dalongxin.work.R;
import com.dalongxin.work.data.SelectionBase;

import java.util.List;

/**
 * 子类别 适配器
 * @author ansen
 * @create time 2015-09-25
 */
public class ChildrenCategoryAdapter extends BaseAdapter {
	private Context mContext;
	private List<SelectionBase> data;

	public ChildrenCategoryAdapter(Context context) {
		mContext = context;
	}

	public void setDatas(List<SelectionBase> data) {
		this.data = data;
	}
	
	@Override
	public int getCount() {
		if(data == null){
			return 0;
		}
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		SelectionBase item = data.get(position);
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_selection_children_category, null);
			holder.children_layout = convertView.findViewById(R.id.children_layout);
			holder.tvChildrenCategoryName = (TextView) convertView.findViewById(R.id.tv_children_category_name);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tvChildrenCategoryName.setText(item.getName());
		if(item.isChecked()) {
			holder.children_layout.setBackgroundResource(R.mipmap.selection_item_press_child);
		}else {
			holder.children_layout.setBackgroundResource(R.mipmap.selection_item_normal);
		}
		return convertView;
	}

	private  class ViewHolder {
		private LinearLayout children_layout;
		private TextView tvChildrenCategoryName;
	}
}
